<?php

header('Content-type: application/json');

if($_FILES["image"]["error"]!=0){
    $result = array('status'=>0,'msg'=>'文件有误！');
    echo json_encode($result);exit();
}

if( !in_array($_FILES["image"]["type"], array('image/gif','image/jpeg','image/bmp','image/png','application/octet-stream')) ){
    $result = array('status'=>0,'msg'=>'文件类型不对');
    echo json_encode($result);exit();
}

if($_FILES["image"]["size"] > 22000000){
    $result = array('status'=>0,'msg'=>'超过大小限制');
    echo json_encode($result);exit();
}

$filename = substr(md5(time()),0,10).mt_rand(1,10000);
$ext = pathinfo($_FILES["image"]["name"], PATHINFO_EXTENSION);

$localName = "./imgs/".$filename.'.'.$ext;

if ( move_uploaded_file($_FILES["image"]["tmp_name"], $localName) == true) {
    $lurl = 'http://localhost/fileUpload/'.$localName;
    $result  = array('status'=>1,'msg'=>$lurl);
}else{
    $result  = array('status'=>0,'msg'=>'error');
}
echo json_encode($result);

?>